<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jstl/core"
      xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:j="http://metalframework.org">
      
	<body>
		<ui:composition template="/WEB-INF/templates/template.xhtml">
			<ui:define name="content">
				<j:keep id="ownerId" value="#{param.ownerId}" />
				<j:keep id="petId" value="#{param.petId}" />
				<j:keep id="currentOwner" value="#{clinic.getOwnerById(ownerId)}" dependsOn="ownerId" />
				<j:keep id="currentPet" value="#{currentOwner.getPetById(petId)}" dependsOn="petId" />
				<j:keep id="currentVisit" value="#{visit}" />

				<h2>New Visit:</h2>
				
				<b>Pet:</b>
				<h:dataTable value="#{currentPet}" var="p" width="350">
					<h:column>
						<f:facet name="header">Name</f:facet>
						<h:outputText value="#{p.name}" />
					</h:column>
					<h:column>
						<f:facet name="header">Birth Date</f:facet>
						<h:outputText value="#{p.birthDate}">
							<f:convertDateTime pattern="yyyy-MM-dd" />
						</h:outputText>
					</h:column>
					<h:column>
						<f:facet name="header">Type</f:facet>
						<h:outputText value="#{p.type}" />
					</h:column>
					<h:column>
						<f:facet name="header">Owner</f:facet>
						<h:outputText value="#{p.owner.firstName} #{p.owner.lastName}" />
					</h:column>
				</h:dataTable>
				
				<br />
				
				<h:form>
					<h:panelGrid columns="2" styleClass="form" width="350">
						<h:column>
							<h:outputLabel value="Date:" for="date" />
							<br />
							<h:message for="date" styleClass="errors" />
						</h:column>
						<h:column>
							<h:inputText value="#{currentVisit.date}" id="date" size="10" maxlength="10">
								<f:convertDateTime pattern="yyyy-MM-dd" timeZone="America/Sao_Paulo" />
							</h:inputText>
							<h:outputText value=" (yyyy-mm-dd)" />
						</h:column>
						<h:column>
							<h:outputLabel value="Description:" for="description" />
							<br />
							<h:message for="description" styleClass="errors" />
						</h:column>
						<h:column>
							<h:inputTextarea value="#{currentVisit.description}" id="description" rows="10" cols="25" />
						</h:column>
						<h:column>
							<span class="submit">
								<h:commandButton action="#{currentPet.takeToVeterinary(currentVisit)}" value="Add Visit" />
							</span>
						</h:column>
					</h:panelGrid>
				</h:form>

				<br />

				<b>Previous Visits:</b>
				<h:dataTable value="#{currentPet.visits}" var="v" width="350">
					<h:column>
						<f:facet name="header">Date</f:facet>
						<h:outputText value="#{v.date}">
							<f:convertDateTime pattern="yyyy-MM-dd" />
						</h:outputText>
					</h:column>
					<h:column>
						<f:facet name="header">Description</f:facet>
						<h:outputText value="#{v.description}" />
					</h:column>
				</h:dataTable>
			</ui:define>
		</ui:composition>
	</body>
</html>
